<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>{$one?'添加':'修改'}功能</title>
    <link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
    <style>
		a.back{color:#ff6a08!important}
		.layui-input-long{width:300px;}
	</style>
</head>
<body>

<form class="layui-form" action="">
    <div class="mainBox">
    	<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-header">
						<a class="pear-btn pear-btn-primary pear-btn-md" onclick="backToList()">
						<i class="pear-icon pear-icon-back"></i>
						返回
						</a>
						<span style="float:right">
						{php} echo empty($one)?'添加':'修改';{/php}功能
						</span>
					</div>
				</div>
			</div>
        <div class="main-container">
            <div class="main-container">
				<div class="layui-form-item">
				    <label class="layui-form-label"></label>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">上级功能</label>
				    <div class="layui-input-inline">
				      <select name="parentid" lay-verify="required">
				        <option value="0">顶级菜单</option>
						{foreach name="list" item="v1"}
						<option value="{$v1['id']}" {if condition="$one.parent eq $v1['id']"}selected{/if}>&nbsp;&nbsp;&nbsp;{$v1['name']}</option>
						{foreach name="v1['sub_menu']" item="v2"}
						<option value="{$v2['id']}" {if condition="$one.parent eq $v2['id']"}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|—— {$v2['name']}</option>
						{foreach name="v2['sub_menu']" item="v3"}
						<option value="{$v3['id']}" {if condition="$one.parent eq $v3['id']"}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|—— {$v3['name']}</option>
						{/foreach}
						{/foreach}
						{/foreach}	
				      </select>
				    </div>

				  </div>
				  
                  <div class="layui-form-item">
				    <label class="layui-form-label">功能名称</label>
				    <div class="layui-input-inline">
				      <input type="text" name="name" value="{$one['name']}" required  lay-verify="required" placeholder="请输入功能名称" autocomplete="off" class="layui-input layui-input-long">
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">代码</label>
				    <div class="layui-input-inline">
				      <input type="text" name="code" value="{$one['code']}" required  lay-verify="required" placeholder="请输入代码" autocomplete="off" class="layui-input layui-input-long">
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">URL地址</label>
				    <div class="layui-input-inline">
				      <input type="text" name="url" value="{$one['url']}" autocomplete="off" class="layui-input layui-input-long">
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">ICON图标</label>
				    <div class="layui-input-inline">
				      <input type="text" name="icon" value="{$one['icon']}" placeholder="" autocomplete="off" class="layui-input layui-input-long">
				    </div>
				  </div>
				  
  				  <div class="layui-form-item">
				    <label class="layui-form-label">排序</label>
				    <div class="layui-input-inline">
				      <input type="text" name="orderby" value="{$one['orderby']?$one['orderby']:$total}" placeholder="请输入数字" autocomplete="off" class="layui-input layui-input-long">
				    </div>
				  </div>
				  
				  <div class="layui-form-item">
				    <label class="layui-form-label">是否显示</label>
				    <div class="layui-input-inline">
				      <input type="radio" name="is_display"  value="1" {if condition="$one['is_display'] eq 1 OR empty($one)"} checked="checked"{/if} title="是" >
						<input type="radio" name="is_display" value="0" {if condition="$one['is_display'] eq 0 AND !empty($one)"} checked="checked"{/if} title="否">
				    </div>
				  </div>
				  
				  <input name="id" type="hidden" value="{$one['id']}"/>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="type-save">
                <i class="layui-icon layui-icon-ok"></i>
                保存
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="__STATIC__/lib/layui/layui.js"></script>
<script src="__PEAR__/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    var path="/{$MODULE_NAME}/Functions/";
	var _url="/saveFunc";
	//返回
	window.backToList=function(){
		window.location.href="{:U('Functions/index')}";
		return false;
	}
	
    form.on('submit(type-save)', function(data){
        $.ajax({
            url:path+_url,
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code){
                    layer.msg(result.msg,{icon:1,time:2000},function(){
                    	location.href = "{:U('Functions/index')}";
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:2000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>